<template>
  <div>
    <!-- 自定义弹窗 -->
    <div v-if="visible" class="custom-dialog">
      <div class="dialog-backdrop" @click="closeDialog"></div>
      <!-- 点击背景关闭弹窗 -->

      <div class="dialog-container">
        <div class="dialog-header">
          <!-- 弹窗标题插槽或默认标题 -->
          <slot name="header">
            <h3 class="dialog-title">{{ title }}</h3>
            <!-- 默认标题 -->
          </slot>
          <!-- 关闭按钮 -->
          <div class="buttons">
            <img
              src="../assets/img/nav/关闭.png"
              @click="closeDialog"
              alt="关闭"
              class="button-icon"
            />
          </div>
        </div>

        <div class="dialog-content">
          <!-- 弹窗内容插槽 -->
          <slot name="content">
            <p>这是默认的弹窗内容，调用方可以通过插槽自定义内容。</p>
          </slot>
        </div>

        <div class="dialog-footer">
          <!-- 弹窗底部插槽或默认关闭按钮 -->
          <slot name="footer">
            <button @click="closeDialog">{{ closeButtonText }}</button>
          </slot>
        </div>
      </div>
    </div>
  </div></template>

<script>
export default {
  props: {
    visible: {
      type: Boolean,
      required: true,
    },
    title: {
      type: String,
      default: "默认标题", // 弹窗默认标题
    },
    closeButtonText: {
      type: String,
      default: "关闭", // 关闭按钮默认文本
    },
  },
  methods: {
    closeDialog() {
      this.$emit("update:visible", false); // 通知父组件关闭弹窗
    },
  },
};
</script>

<style scoped>
/* 弹窗背景 */
.custom-dialog {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

/* 弹窗背景遮罩 */
.dialog-backdrop {
  position: absolute;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.7); /* 半透明黑色背景 */
}

/* 弹窗容器 */
.dialog-container {
  position: relative;
  width: 80%; /* 弹窗宽度 */
  height: 80%;
  background-image: url("../assets/img/test/bg_border.png"); /* 背景图片 */
  background-size: cover;
  padding: 20px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3); /* 阴影效果 */
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

/* 弹窗顶部标题和按钮 */
.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.dialog-title {
  font-size: 1.5rem;
  margin: 0;
}

.buttons {
  display: flex;
  gap: 5px;
}

.button-icon {
  width: 40px;
  height: 40px;
  cursor: pointer;
}

/* 弹窗内容区 */
.dialog-content {
  margin-top: 20px;
  flex-grow: 1; /* 内容区域弹性布局 */
  overflow-y: auto; /* 当内容过多时启用滚动条 */
}

/* 弹窗底部按钮 */
.dialog-footer {
  display: flex;
  /* justify-content: flex-end; */
  gap: 10px;
}

/* .dialog-footer button {
  padding: 10px 20px;
  background-color: #007bff;
  color: white;
  border: none;
  cursor: pointer;
  border-radius: 5px;
} */
.dialog-footer {
  display: flex;
  justify-content: center; /* Ensure buttons are centered */
  gap: 20px; /* Space between buttons */
  margin-top: 20px;
}

.dialog-footer button:hover {
  background-color: #0056b3;
}
</style>